"use strict";
cc._RF.push(module, 'abd535V9VRCVIsOFtrle6kt', 'block');
// script/block.js

"use strict";

cc.Class({
  "extends": cc.Component,
  properties: {},
  onLoad: function onLoad() {},
  init: function init(i_type) {
    this.block_type = i_type;
    this.can_pz = true; //是否可以碰撞

    this.is_pz = false; //是否发生过碰撞

    if (i_type >= 11 || i_type <= 0) {
      this.can_pz = false; //是否可以碰撞
    }

    this.i_over = 0;
  },
  // 只在两个碰撞体开始接触时被调用一次
  onBeginContact: function onBeginContact(contact, selfCollider, otherCollider) {
    //console.log('只在两个碰撞体开始接触时被调用一次');
    if (otherCollider.tag != 11) {
      this.is_pz = true;
    }

    var js_otherBlock = otherCollider.node.getComponent('block');

    if (js_otherBlock && this.can_pz && js_otherBlock.can_pz) {
      if (this.block_type == js_otherBlock.block_type) {
        this.can_pz = false;
        js_otherBlock.can_pz = false;
        var pos_self = this.node.getPosition();
        var pos_other = otherCollider.node.getPosition();
        var pos_min = pos_self;

        if (pos_min.y > pos_other.y) {
          pos_min = pos_other;
        }

        this.node.removeFromParent();
        otherCollider.node.removeFromParent();
        game.playSound();
        {
          var block_wh = this.node.width;
          game.createTx(this.block_type, pos_self, block_wh);
          game.createTx(this.block_type, pos_other, block_wh);
        }

        if (game.i_game == 1) {
          //大
          game.addScore(this.block_type);
        } else {
          //小
          var i_score = 11 - this.block_type;
          game.addScore(i_score);
        }

        this.scheduleOnce(function () {
          if (game.i_game == 1) {
            //大
            game.createBlock(this.block_type + 1, pos_min, true);
          } else {
            game.createBlock(this.block_type - 1, pos_min, true);
          }
        }.bind(this), 0.15);
      }
    }
  },
  // 只在两个碰撞体结束接触时被调用一次
  onEndContact: function onEndContact(contact, selfCollider, otherCollider) {},
  // 每次将要处理碰撞体接触逻辑时被调用
  onPreSolve: function onPreSolve(contact, selfCollider, otherCollider) {},
  // 每次处理完碰撞体接触逻辑时被调用
  onPostSolve: function onPostSolve(contact, selfCollider, otherCollider) {},
  update: function update(dt) {
    if (game.is_over) {
      return;
    }

    var y_gao = this.node.y + this.node.height * game.f_scale / 2;

    if (y_gao > game.node_xian.y) {
      this.i_over++;

      if (this.i_over > 120) {
        game.gameOver();
      }
    } else {
      this.i_over = 0;
    }
  }
});

cc._RF.pop();